//
//  YHMeOrderListCell.m
//  YHApp
//
//  Created by -- on 2021/8/27.
//

#import "HAOrderListCell.h"
#import "HAOrderMo.h"
#import "HAShoppingMallMo.h"

@interface HAOrderListCell ()

/***/
@property (nonatomic, strong) UIView *mainView;
/***/
@property (nonatomic, strong) UIView *lineView;
/***/
@property (nonatomic, strong) UIButton *delegeteButton;
/***/
@property (nonatomic, strong) UILabel *orderNumLabel;
/***/
@property (nonatomic, strong) UILabel *statusLabel;
/***/
@property (nonatomic, strong) UIImageView *iconImgView;
/***/
@property (nonatomic, strong) UILabel *nameLabel;
/***/
@property (nonatomic, strong) UILabel *numLabel;
/***/
@property (nonatomic, strong) UILabel *picLabel;

@end

@implementation HAOrderListCell

-(void)delegeteButtonClick {
    
}

-(void)setModel:(HAOrderMo *)model {
    _model = model;
    
    self.orderNumLabel.text = [NSString stringWithFormat:@"订单编号:%@",_model.sn];
    self.statusLabel.text = _model.sate;
    self.nameLabel.text = _model.title;
    self.numLabel.text = [NSString stringWithFormat:@"%@%@",_model.num,_model.unit];
    if (_model.item.count > 0) {
        HAShoppingMallMo *mo = _model.item.firstObject;
        [self.iconImgView sd_setImageWithURL:[NSURL URLWithString:mo.url]];
    }
    self.picLabel.text = [NSString stringWithFormat:@"￥%@",_model.total];
}

-(void)layoutSubviews {
    [super layoutSubviews];
    
    self.contentView.backgroundColor = [UIColor khaBGColor];
    
    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.top.mas_equalTo(5);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_offset(1);
        make.top.mas_equalTo(31);
    }];
    
    [self.delegeteButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_offset(42);
        make.height.mas_offset(30);
        make.top.mas_equalTo(0);
        make.right.mas_equalTo(-20);
    }];
    
    if (self.isD) {
        self.delegeteButton.hidden = YES;
    }else {
        self.delegeteButton.hidden = NO;
    }
    
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.delegeteButton);
        if (self.isD) {
            make.right.mas_equalTo(-20);
        }else {
            make.right.equalTo(self.delegeteButton.mas_left).offset(-5);
        }
        make.width.mas_offset(78);
    }];
    
    [self.orderNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.delegeteButton);
        make.left.mas_equalTo(20);
        make.right.equalTo(self.statusLabel.mas_left).offset(-5);
    }];
    
    [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.lineView.mas_bottom).offset(10);
        make.left.mas_equalTo(20);
        make.width.mas_offset(72);
        make.height.mas_offset(54);
    }];
    
    [self.picLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.iconImgView);
        make.right.mas_equalTo(-20);
        make.width.mas_offset(102);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.iconImgView.mas_right).offset(15);
        make.right.mas_equalTo(self.picLabel.mas_left).offset(-5);
        make.centerY.mas_equalTo(self.iconImgView).offset(-15);
    }];
    
    [self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.iconImgView.mas_right).offset(15);
        make.right.mas_equalTo(self.picLabel.mas_left).offset(-5);
        make.centerY.mas_equalTo(self.iconImgView).offset(15);
    }];
    

    
}

- (UIView *)mainView
{
    if (!_mainView) {
        _mainView = [UIView ha_createView];
        _mainView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_mainView];
    }
    return _mainView;
}

- (UIView *)lineView
{
    if (!_lineView) {
        _lineView = [UIView ha_createView];
        _lineView.backgroundColor = [UIColor khaBGColor];
        [self.mainView addSubview:_lineView];
    }
    return _lineView;
}

- (UIButton *)delegeteButton
{
    if (!_delegeteButton) {
        _delegeteButton = [[UIButton alloc]init];
        [_delegeteButton setTitle:@"删除" forState:UIControlStateNormal];
        [_delegeteButton setTitleColor:[UIColor colorWithHexString:@"#5f67fc"] forState:UIControlStateNormal];
        _delegeteButton.titleLabel.font = [UIFont systemFontOfSize:12];
        [_delegeteButton addTarget:self action:@selector(delegeteButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [self.mainView addSubview:_delegeteButton];
//        [_delegeteButton setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal]
    }
    return _delegeteButton;
}

- (UILabel *)orderNumLabel
{
    if (!_orderNumLabel) {
        _orderNumLabel = [UILabel ha_NLabelWithFont:13 textColor:@"#858b9c" text:@"" alignment:0];
        [self.mainView addSubview:_orderNumLabel];
    }
    return _orderNumLabel;
}

- (UILabel *)statusLabel
{
    if (!_statusLabel) {
        _statusLabel = [UILabel ha_BLabelWithFont:12 textColor:@"#000000" text:@"" alignment:2];
        [self.mainView addSubview:_statusLabel];
    }
    return _statusLabel;
}

- (UIImageView *)iconImgView
{
    if (!_iconImgView) {
        _iconImgView = [UIImageView ha_createImageView];
        _iconImgView.contentMode = UIViewContentModeScaleAspectFill;
        _iconImgView.clipsToBounds = YES;
        [self.mainView addSubview:_iconImgView];
    }
    return _iconImgView;
}

- (UILabel *)nameLabel
{
    if (!_nameLabel) {
        _nameLabel = [UILabel ha_NLabelWithFont:17 textColor:@"#111a34" text:@"" alignment:0];
        [self.mainView addSubview:_nameLabel];
    }
    return _nameLabel;
}

- (UILabel *)numLabel
{
    if (!_numLabel) {
        _numLabel = [UILabel ha_NLabelWithFont:12 textColor:@"#858b9c" text:@"" alignment:0];
        [self.mainView addSubview:_numLabel];
    }
    return _numLabel;
}

- (UILabel *)picLabel
{
    if (!_picLabel) {
        _picLabel = [UILabel ha_NLabelWithFont:14 textColor:@"#000000" text:@"" alignment:2];
        [self.mainView addSubview:_picLabel];
    }
    return _picLabel;
}



@end
